package com.jbp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jbp.dao.ProtectGiftsDao;
import com.jbp.model.ProtectGifts;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ProtectGiftsService extends ServiceImpl<ProtectGiftsDao, ProtectGifts> implements IService<ProtectGifts> {


    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ProtectGifts> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null) {
            queryWrapper.like("id",params.get("id"));
        }
        if (params.get("normalGiftId") != null) {
            queryWrapper.like("normal_gift_id",params.get("normalGiftId"));
        }
        if (params.get("normalCoin") != null) {
            queryWrapper.like("normal_coin",params.get("normalCoin"));
        }
        if (params.get("laterGiftId") != null) {
            queryWrapper.like("later_gift_id",params.get("laterGiftId"));
        }
        if (params.get("laterCoin") != null) {
            queryWrapper.like("later_coin",params.get("laterCoin"));
        }
        if (params.get("userPacksackId") != null) {
            queryWrapper.like("user_packsack_id",params.get("userPacksackId"));
        }
        if (params.get("userDailyLuckRecordId") != null) {
            queryWrapper.like("user_daily_luck_record_id",params.get("userDailyLuckRecordId"));
        }
        if (params.get("lotteryRecordId") != null) {
            queryWrapper.like("lottery_record_id",params.get("lotteryRecordId"));
        }
        if (params.get("flag") != null) {
            queryWrapper.like("flag",params.get("flag"));
        }
        if (params.get("createTime") != null) {
            queryWrapper.like("create_time",params.get("createTime"));
        }
        if (params.get("updateTime") != null) {
            queryWrapper.like("update_time",params.get("updateTime"));
        }
        if (params.get("fromDate")!=null) {
            queryWrapper.ge("create_time", params.get("fromDate"));
        }
        if (params.get("toDate")!=null) {
            queryWrapper.le("DATE_FORMAT(create_time,   '%Y-%m-%d')", params.get("toDate"));
        }
        queryWrapper.orderByDesc("id");
        IPage<ProtectGifts> page = this.page(
            new Query<ProtectGifts>().getPage(params), queryWrapper
        );
        return new PageUtils(page);
    }
}